package com.power.structure.queue;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/14 11:40 上午
 */
public class DoubleLinkedQueue {

    private Node head;
    private Node tail;
    private int value;
    private int size;

    class Node {
        Node pre;
        Node next;
        int value;

        public Node(int value) {
            this.value = value;
        }
    }


    public void enQueue(int value) {
        Node node = new Node(value);

        if (head == null) {
            tail = head = node;
        } else {
            tail.next = node;
            tail = node;
        }
        size++;
    }

    //队列  先进先出
    public Integer deQueue() {
        int res = head.value;
        head = head.next;
        size--;
        return res;
    }

    public int size() {
        return size;
    }

    public void display() {
        Node node = head;
        while (node != null) {
            System.out.print(" " + node.value);
            node = node.next;
        }
        System.out.println("\n");
    }

    public static void main(String[] args) {
        DoubleLinkedQueue doubleLinkedQueue = new DoubleLinkedQueue();
        for (int i = 0; i < 10; i++) {
            doubleLinkedQueue.enQueue(i);
        }
        doubleLinkedQueue.display();

        for (int i = 0; i < 10; i++) {
            doubleLinkedQueue.deQueue();
            doubleLinkedQueue.display();
        }


    }

}
